﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using SocialPhotos.Models;
using SocialPhotos.Models.Entities;

namespace SocialPhotos.Widgets.TopRatePhotos
{
    public class PhotoTopRateCotroller : IPhotoTopRateController
    {
        private  readonly  EfDbContext _efDbContext = new EfDbContext();

        public  PhotoTopRateViewModel GetViewModel (int size)
        {
            PhotoTopRateViewModel viewModel = new PhotoTopRateViewModel();
            var query = this._efDbContext.Photos.Select(p => p).OrderByDescending(p => p.Likes).Take(size);
            viewModel.ModuleHeader = "Top rating photo";
            viewModel.Photos = query.ToList();
            return viewModel;
        }
    }
}